#if !defined(PG_COPY_GUARD_H)
#define PG_COPY_GUARD_H

// pg_copy_guard.h
//


#include <iosfwd>
#include <string>

class t_pg_cursor;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//		t_pg_copy_guard

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include <sstream>
class t_pg_copy_guard
{
	t_pg_cursor&	pg_db;
	std::string		table_name;
	std::ostream&	CERR;
	bool			proceeding;
	bool			success;
public:
	std::string		buf;
	
	t_pg_copy_guard(t_pg_cursor& pg_db_, const std::string& table_name_, std::ostream& CERR_);
	~t_pg_copy_guard(){if (proceeding) end_copy();}
	void cached_write();
	void write();
	operator bool() const { return success; }
    t_pg_copy_guard&
    operator+=(const std::string& str) { buf += str; return *this;}
    t_pg_copy_guard&
    operator+=(const char* str) { buf += str; return *this;}
    t_pg_copy_guard&
    operator+=(const char c) { buf += c; return *this;}

	bool end_copy();

};


#endif //PG_COPY_GUARD_H
